# -*- coding: utf-8 -*-
import pymongo
import datetime


def string_to_date(date):
    '''将日期字符串转换为日期
    '''
    return datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")


def process_db(db_addr, db_port, db_name, process_func):
    '''打开Collection并处理
    '''
    client = pymongo.MongoClient(db_addr, db_port)
    db = client[db_name]
    process_func(db)
    client.close()
